package com.igoal.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableProperty;

@Entity
@Table(name="company")
@Searchable
public class Company extends BaseObject implements Audit {
	private static final long serialVersionUID = -1209448181496238545L;
	
	private Long id;
	private String name;
	private City city;
	private String field;
	private String title;
	private Date createDate;
	private Date updateDate;
	private DataStatus status;
	
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(name = "name", nullable = false)
	@SearchableProperty
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "city_id")
	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}
	
	@Column(name = "field", nullable = true)
	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}
	
	@Column(name = "title", nullable = true)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Override
	public boolean equals(Object o) {
		if(o != null){
			Company that = (Company) o;
			return id.equals(id) && city.equals(that.city) && name.equals(name);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return id.hashCode() + city.hashCode();
	}

	@Override
	public String toString() {
		return "Company " + name;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "cdate", nullable = false, length = 19)
	public Date getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(Date date) {
		this.createDate = date;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, name = "mdate")
	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date date) {
		this.updateDate = date;
	}

	@Enumerated(EnumType.STRING)
	@Column(name = "status", nullable = false, length = 50)
	public DataStatus getStatus() {
		return this.status;
	}

	public void setStatus(DataStatus status) {
		this.status = status;
	}

}
